###################################
### This is an example to access Interactive Brokers API
###################################

## NOTE: Before running the code, open an Interactive Brokers Trade Workstation
## Go to File->Global Configuration, Check "Enable ActiveX and Socket Clients",
## also add a trusted IP 127.0.0.1

## install the necessary library
library(IBrokers)
tws <- twsConnect()

# create contract AAPL from NASDAQ
contract <- twsEquity('AAPL','SMART','ISLAND')
# default is 30 days historical data
res <- reqHistoricalData(tws, Contract=contract)

# close connection
twsDisconnect(tws)

